import { createBrowserRouter } from 'react-router-dom';
import { lazy } from 'react';
import { lazyLoad } from './LazyLoad';
import Login from '@/pages/Login/Login.tsx';

const router = createBrowserRouter([
  {
    // 用户端
    path: '/',
    element: lazyLoad(lazy(() => import('../App'))), // 用户提供加载状态
    children: [
      // 首页
      {
        path: '/',
        element: lazyLoad(
          lazy(() => import('../pages/Home/Home')),
          true
        ),
      },
      // 文章分类
      {
        path: '/categories',
        children: [
          {
            path: '/categories',
            element: lazyLoad(
              lazy(() => import('../pages/Categories/Categories')),
              true
            ),
          },
          {
            path: '/categories/:id',
            element: lazyLoad(
              lazy(() => import('../pages/Categories/CategoriesItem/CategoriesItem'))
            ),
          },
        ],
      },
      // 用户中心
      {
        path: '/profile',
        element: lazyLoad(
          lazy(() => import('../pages/Profile/Profile.tsx')),
          true
        ),
      },
      // 商城
      {
        path: '/business',
        element: lazyLoad(
          lazy(() => import('../pages/Business/Business')),
          true
        ),
      },
      // 购物车
      {
        path: '/cart',
        element: lazyLoad(lazy(() => import('../pages/Cart/Cart'))),
      },
    ],
  },
  {
    path: '/login',
    element: <Login />,
  },
  // 管理员端
  {
    path: '/admin',
    element: lazyLoad(lazy(() => import('../pages/Admin/Admin'))),
    children: [
      // 管理员登录
      {
        path: '/admin/login',
        element: lazyLoad(lazy(() => import('../pages/Admin/pages/Login/Login'))),
      },
      // 管理员首页
      {
        path: '/admin',
        element: lazyLoad(lazy(() => import('../pages/Admin/pages/Home/Home'))),
        children: [
          {
            path: '/admin/home',
            element: lazyLoad(lazy(() => import('../pages/Admin/pages/HomeContent/HomeContent'))),
          },
          {
            path: '/admin/user',
            element: lazyLoad(lazy(() => import('../pages/Admin/pages/User/User'))),
          },
          {
            path: '/admin/business',
            element: lazyLoad(lazy(() => import('../pages/Admin/pages/Business/Business'))),
          },
          {
            path: '/admin/article',
            element: lazyLoad(lazy(() => import('../pages/Admin/pages/Article/Article'))),
          },
        ],
      },
    ],
  },
  // 未找到页面
  {
    path: '*',
    element: lazyLoad(lazy(() => import('../pages/NotFound/NotFound'))),
  },
]);

export default router;
